<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <div id="community">
        <div id="forum-header">
            <?php echo $community_header; ?>
        </div>
        <?php if(!$show_result){ ?>
        <div class="search">
            <dl>
                <dt><strong><?php echo $text_search_query; ?></strong></dt>
                <dd>
                    <span><strong><?php echo $entry_keyword; ?></strong><br /><?php echo $text_keyword_tip; ?></span>
                    <input class="input-text" type="text" name="keyword" id="keyword" value="" />
                </dd>
                <dd>
                    <span><strong><?php echo $entry_author; ?></strong><br /><?php echo $text_author_tip; ?></span>
                    <input class="input-text" type="text" name="author" value="" />
                </dd>
            </dl>
        </div>
        <div class="search">
            <dl>
                <dt><strong><?php echo $text_search_option; ?></strong></dt>
                <dd>
                    <span><strong><?php echo $entry_search_forum ?></strong></span>
                    <select id="select-forum" name="forum" multiple="multiple">
                        <?php if($forums){ ?>
                        <option value="all" selected="selected"><?php echo $text_all_open_fourms; ?></option>
                        <?php foreach($forums as $forum){ ?>
                        <option value="<?php echo $forum['forum_id']; ?>"><?php echo $forum['forum_name']; ?></option>
                            <?php if(isset($sub_forums[$forum['forum_id']])){ ?>
                            <?php foreach($sub_forums[$forum['forum_id']] as $sub_forum){ ?>
                            <option value="<?php echo $sub_forum['forum_id']; ?>"><?php echo $sub_forum['forum_name']; ?></option>
                            <?php } ?>
                            <?php } ?>
                        <?php } ?>
                        <?php }else{ ?>
                        <?php } ?>
                    </select>
                </dd>
                <dd>
                    <span><strong><?php echo $entry_search_within; ?></strong></span>
                    <select name="within">
                        <option value="psm"><?php echo $text_post_subject_message; ?></option>
                        <option value="ps"><?php echo $text_post_subject_only; ?></option>
                        <option value="pm"><?php echo $text_post_message_only; ?></option>
                        <option value="tsm"><?php echo $text_topic_subject_message; ?></option>
                        <option value="ts"><?php echo $text_topic_subject_only; ?></option>
                        <option value="tm"><?php echo $text_topic_message_only; ?></option>
                    </select>
                </dd>
                <dd>
                    <span><strong><?php echo $entry_sort_by; ?></strong></span>
                    <select name="sort">
                        <option value="lpt"><?php echo $text_last_post_time; ?></option>
                        <option value="tt"><?php echo $text_topic_time; ?></option>
                        <option value="tv"><?php echo $text_topic_views; ?></option>
                        <option value="tr"><?php echo $text_topic_replies; ?></option>
                        <option value="f"><?php echo $text_forum; ?></option>
                        <option value="a"><?php echo $text_author; ?></option>
                    </select>
                    <input class="input-radio" type="radio" name="order" value="desc" checked="checked" /><?php echo $text_descending; ?>&nbsp;
                    <input class="input-radio" type="radio" name="order" value="asc" /><?php echo $text_ascending; ?>
                </dd>
                <dd>
                    <span><strong><?php echo $entry_search_time_limit; ?></strong></span>
                    <select name="time">
                        <option value="all"><?php echo $text_all_result; ?></option>
                        <option value="1d"><?php echo $text_one_day; ?></option>
                        <option value="1w"><?php echo $text_one_week; ?></option>
                        <option value="2w"><?php echo $text_two_week; ?></option>
                        <option value="1m"><?php echo $text_one_month; ?></option>
                        <option value="3m"><?php echo $text_three_month; ?></option>
                        <option value="6m"><?php echo $text_six_month; ?></option>
                        <option value="1y"><?php echo $text_one_year; ?></option>
                    </select>
                </dd>
                <dd style="text-align:center;">
                    <input class="input-buttons" type="button" id="search-submit" value="<?php echo $button_search; ?>" />
                </dd>
            </dl>
        </div>
        <?php }else{ ?>
        <div id="result-match"><?php echo $text_found_matches; ?></div>
        <div class="forum-pagination"><?php echo $pagination; ?></div>
        <div id="result">
            <?php if($results){ ?>
            <?php foreach($results as $result){ ?>
            <div class="result-list">
                <div class="result-list-left">
                        <a style="font-size:16px;font-weight:bold;" href="<?php echo $result['post_link']; ?>"><?php echo $result['post_subject']; ?></a><br />
                        <?php echo $result['post_text']; ?>
                </div>
                <div class="result-list-right">
                        <?php echo $text_by; ?> <a href="<?php echo $result['user_link']; ?>"><?php echo $result['username']; ?></a><br />
                        <?php echo $result['post_time']; ?><br />
                        <?php echo $text_forum; ?> <a href="<?php echo $result['forum_link']; ?>"><?php echo $result['forum_name']; ?></a><br />
                        <?php echo $text_topic; ?> <a href="<?php echo $result['topic_link']; ?>"><?php echo $result['topic_title']; ?></a><br />
                        <?php echo $text_views; echo $result['topic_views']; ?><br />
                        <?php echo $text_replies; echo $result['topic_replies']; ?>
                </div>
            </div>
            <?php } ?>
            <?php }else{ ?>
            <div style="text-align:center;">
                <?php echo $text_no_result; ?>
            </div>
            <?php } ?>
        </div>
        <div class="forum-pagination"><?php echo $pagination; ?></div>
        <?php } ?>
    </div>
    <?php  echo $footer; ?>
<script type="text/javascript"><!--
$('#community input[name=\'keyword\']').keydown(function(e) {
    if (e.keyCode == 13) {
        $('#search-submit').trigger('click');
    }
});

$('#community input[name=\'author\']').keydown(function(e) {
    if (e.keyCode == 13) {
        $('#search-submit').trigger('click');
    }
});

$('#community input[name=\'header-keyword\']').keydown(function(e) {
    if (e.keyCode == 13) {
        $('#header-search-button').trigger('click');
    }
});

$('#search-submit').bind('click', function() {
url = 'index.php?route=community/search';

var keyword = $('#community input[name=\'keyword\']').attr('value');

url += '&kw=' + encodeURIComponent(keyword);


var author = $('#community input[name=\'author\']').attr('value');

if (author) {
    url += '&au=' + encodeURIComponent(author);
}

var forum = $('#community select[name=\'forum\']').attr('value');

if (forum > 0) {
url += '&if=' + encodeURIComponent(forum);
}

var within = $('#community select[name=\'within\']').attr('value');

if (within) {
    url += '&sw=' + encodeURIComponent(within);
}

var sort = $('#community select[name=\'sort\']').attr('value');

if (sort) {
    url += '&sb=' + encodeURIComponent(sort);
}

var order = $('#community input[name=\'order\']:checked').attr('value');

if (order) {
url += '&or=' + encodeURIComponent(order);
}

var time = $('#community select[name=\'time\']').attr('value');

if (time) {
    url += '&lr=' + encodeURIComponent(time);
}

location = url;
});

$('#header-search-button').bind('click', function() {
    url = 'index.php?route=community/search';

    var keyword = $('#forum-header-bar-search input[name=\'header-keyword\']').attr('value');

    url += '&kw=' + encodeURIComponent(keyword) + '&sw=psm&sb=lpt&or=desc&lr=all';

    location = url;
});

$(document).ready(
    function(){
        $(".result-list").filter(":even").mouseover(function() {
            $(this).css("background-color", "#FFFFDB");
        }).mouseout(function(){
                $(this).css("background-color", "");
            });

        $(".result-list").filter(":odd").mouseover(function() {
            $(this).css("background-color", "#FFFFDB");
        }).mouseout(function(){
                $(this).css("background-color", "");
            });
    });
//--></script>